package comment

import (
	"net/http"
	"strconv"

	"gitee.com/zoneaurora/shop/internal/common"
	"gitee.com/zoneaurora/shop/internal/dto"
	"gitee.com/zoneaurora/shop/internal/logic/admin/base"
	"gitee.com/zoneaurora/shop/internal/model"

	"github.com/gin-gonic/gin"
)

type CommentLogic struct {
	base.BaseLogic[model.Comment]
}

func NewCommentLogic() *CommentLogic {
	return &CommentLogic{
		BaseLogic: base.BaseLogic[model.Comment]{
			DB: common.DB(),
		},
	}
}

func (cl *CommentLogic) Options(c *gin.Context) {
  var connectOrders []model.Order
  // 获取订单数据
  if err := cl.DB.Find(&connectOrders).Error; err != nil {
    common.JSON(c, http.StatusInternalServerError, "查询数据失败", nil)
  }
  var orders []dto.SelectItem
  for _, v := range connectOrders {
    var item dto.SelectItem
    item.Label = strconv.FormatUint(uint64(v.ID), 10)
    item.Value = v.ID
    orders = append(orders, item)
  }

  // 获取产品数据
  var connectProducts []model.Product
  if err := cl.DB.Find(&connectProducts).Error; err != nil {
    common.JSON(c, http.StatusInternalServerError, "查询数据失败", nil)
  }
  var products []dto.SelectItem
  for _, v := range connectProducts {
    var item dto.SelectItem
    item.Label = strconv.FormatUint(uint64(v.ID), 10)
    item.Value = v.ID
    products= append(products, item)
  }

	var commentModel model.Comment
	common.JSON(c, http.StatusOK, "查询数据成功", gin.H{
		"model": commentModel,
		"connection": gin.H{
			"OrderID":   orders,
			"ProductID": products,
		},
	})
}
